package engine

import (
	"FlyFight/route"
	"log"
	"time"
	"github.com/gin-contrib/cors"
	"github.com/gin-gonic/gin"
)

type httpserver struct{
	r *gin.Engine
}

func (h *httpserver)Init() {
	h.r=gin.Default()
	// h.r.SetTrustedProxies([]string{
	// "http://127.0.0.1",	
	// "https://114.116.227.230",
	// "http://10.12.56.110",
	// })
	h.r.Use(cors.New(cors.Config{
		AllowOrigins:     []string{
		"http://localhost:5173",
		"http://code-help.top:3778",
		"http://www.code-help.top:3778",
		}, // 白名单
		AllowMethods:     []string{"GET", "POST", "PUT", "PATCH","OPTIONS"},
		AllowHeaders:     []string{"Origin", "Content-Type", "Authorization"},
		ExposeHeaders:    []string{"Content-Length"},
		AllowCredentials: true,
		MaxAge:           2 * time.Hour,
	}))
	route.UseRoot(h.r)
}
 
func (h *httpserver)Run(){
	err:=h.r.Run(":3777")
	if err!=nil{
		log.Println("err")
	}
	
}